import { ModalForm, ProFormTextArea } from '@ant-design/pro-components';
import { message } from 'antd';
import { cancelMember } from '../service';

const CancelRecord = (props: { reload: () => void; recordId: string }) => {
  const { recordId, reload } = props;
  return (
    <ModalForm
      title="作废订单"
      width="40vw"
      layout="horizontal"
      trigger={<a>作废</a>}
      onFinish={async (values) => {
        if (!values.reason) {
          message.warn({ key: 'cancel_memeber', content: '请填写作废原因' });
          return false;
        }
        const res = await cancelMember({ id: recordId, reason: values.reason });
        if (!res.success) {
          message.error({ key: 'cancel_memeber', content: res.message });
          return false;
        }
        reload();
        message.success({ key: 'cancel_memeber', content: res.message });
        return true;
      }}
    >
      <ProFormTextArea label="作废原因" name="reason" required />
    </ModalForm>
  );
};

export default CancelRecord;
